package day2;

import java.util.Random;
import java.util.Scanner;

import org.junit.Test;

public class WhileForDemo {

	@Test
	public void test1() {
//		while (true) {
//			System.out.println("WhileDemo.test1()");
//		}
		for (;;) {
			System.out.println("WhileDemo.test1()");
		}
	}

	@Test
	public void test2() {
		// Ctrl+Alt+向下箭头
		// 1、循环条件的初始化
		int i = 1;
		// 2、循环条件的控制
		while (i <= 5) {
			System.out.println("HelloWorld");
			// 3、循环条件的改变
			i++;
		}
	}

	@Test
	public void test3() {
		for (int i = 1; i <= 5; i++) {
			System.out.println("HelloWorld");
		}
	}

	// 累加思想
	@Test
	public void test4() {
		int i = 1;
		int sum = 0;
		while (i <= 100) {
			System.out.println(i);
			sum = sum + i; // sum += i;
			i++;
		}
		System.out.println("sum: " + sum);
	}

	@Test
	public void test5() {
		int sum = 0;
		for (int i = 1; i <= 100; i++) {
			sum += i;
		}
		System.out.println("sum: " + sum);
	}

	@Test
	public void test6() {
		int count = 0;
		for (int i = 1; i <= 100; i++) {
			if (i % 7 == 0) {
				System.out.println(i);
				count++;
			}
		}
		System.out.println("count: " + count);
	}

	@Test
	public void test7() {
		// 4*9=36
		for (int i = 1; i <= 9; i++) {
			// 豆豆加加
			// System.out.print("4*9=36 ");
			System.out.print(i + "*9=" + (i * 9) + " ");
		}
	}

	@Test
	public void test34() {
		for (int i = 1; i <= 10; i++) {
			if (i == 3) {
				continue;
			}
			System.out.println(i);
		}
	}

	@Test
	public void test35() {
		for (int i = 1; i <= 10; i++) {
			if (i == 3) {
				break;
			}
			System.out.println(i);
		}
		System.out.println("WhileForDemo.test35()");
	}

	@Test
	public void test36() {
		// i,j,k
		for (int i = 1; i <= 10; i++) {
			for (int j = 1; j <= 10; j++) {
				if (j == 3) {
					break;
				}
				System.out.println(j);
			}
		}
		System.out.println("WhileForDemo.test35()");
	}

	@Test
	public void test55() {
		Scanner scanner = new Scanner(System.in);
		// 0=<random<100 + 1
		// 1=<random<=100
		int random = new Random().nextInt(100) + 1;
		System.out.println(random);
		while (true) {
			// Unreachable code
			System.out.println("猜吧");
			int num = scanner.nextInt();
			// 非法输入、退出操作
			if (num == 0) {
				System.out.println("退出");
				break;
			}

			if (num > random) {
				System.out.println("太大了");
			} else if (num < random) {
				System.out.println("太小了");
			} else {
				System.out.println("恭喜你，猜对了");
				break;
			}
		}
	}

	@Test
	public void test344() {
		Scanner scanner = new Scanner(System.in);
		while (true) {
			System.out.println("请输入月份：");
			int month = scanner.nextInt();
			// 如果输入合法，就退出
			if (month >= 1 && month <= 12) {
				break;
			}

			System.out.println("输入的月份非法");

		}
	}

	@Test
	public void test44() {
		// >=90 <=100 优秀
		// >=80 <90 良好
		// >=70 <80 一般
		// >=60 <70 及格
		// <60 不及格
		Scanner scanner = new Scanner(System.in);
		System.out.println("请输入成绩：");
		// alt+shift+L
		int score = scanner.nextInt();
		if (score < 0 || score > 100) {
			System.out.println("成绩非法");
			return;
		}

		switch (score / 10) {
		case 9:
		case 10:
			System.out.println("优秀");
			break;
		case 8:
			System.out.println("良好");
			break;
		case 0:
		case 1:
		case 2:
		case 3:
		case 4:
		case 5:
			System.out.println("不及格");
			break;
		default:
			break;
		}
	}
	
	@Test
	public void test43() {
		for (;;) {
			
		}
//		while (true) {
//			
//		}
		// 不管条件是不是成功，都要执行一次
//		do {
//			
//		} while (true);
	}
	
	
	

}
